package com.example.demo.util;

import com.example.demo.mapper.DeviceMapper;
import com.example.demo.pojo.excel.Excel;
import com.example.demo.pojo.zuwang.zuwang.Device;
import com.example.demo.pojo.zuwang.zuwang.ZuWangFromJSRes;

public class CheckDeviceState {

//    public static void updateDeviceUnZuwang(DeviceMapper deviceMapper, ExcelMapper excelMapper, String deviceUni) {
//
//        Device device = deviceMapper.selectByUni(deviceUni);
//        //未识别如果excel有值 改为未组网
//        if (device != null && device.getState().equals(DeviceStateEnum.NO_DEVICE.getType())) {
//            Excel seExcel = new Excel();
//            seExcel.setDevice(device.getDevice());
//            seExcel.setSn(device.getSn());
//            Integer i = excelMapper.selectExcel(seExcel);
//            if (i > 0) {
//                device.setState(DeviceStateEnum.UN_ZUWANG.getType());
//                //excel上传触发 为空是接入设备的时候触发
//                deviceMapper.updateState(device);
//            }
//        }
//    }

    public static void setDeviceName(String deviceId, Device device) {

        if (deviceId.equals(DeviceEnum.JICHENG.getDeviceId())) {
            device.setDeviceName(DeviceEnum.JICHENG.getDeviceName());
        } else if (deviceId.equals(DeviceEnum.JIESHOU.getDeviceId())) {
            device.setDeviceName(DeviceEnum.JIESHOU.getDeviceName());
        } else if (deviceId.equals(DeviceEnum.REMOTE_CONTROL.getDeviceId())) {
            device.setDeviceName(DeviceEnum.REMOTE_CONTROL.getDeviceName());
        }
    }

    public static void setExcelName(String deviceId, Excel excel) {

        if (deviceId.equals(DeviceEnum.JICHENG.getDeviceId())) {
            excel.setDeviceName(DeviceEnum.JICHENG.getDeviceName());
        } else if (deviceId.equals(DeviceEnum.JIESHOU.getDeviceId())) {
            excel.setDeviceName(DeviceEnum.JIESHOU.getDeviceName());
        } else if (deviceId.equals(DeviceEnum.REMOTE_CONTROL.getDeviceId())) {
            excel.setDeviceName(DeviceEnum.REMOTE_CONTROL.getDeviceName());
        }
    }

    /**
     * 未组网的改为正常
     *
     * @param deviceMapper
     * @param unZuwangDevice
     * @param zuWangFromJSRes
     */
    public static void updateDeviceZuwang(DeviceMapper deviceMapper, Device unZuwangDevice, ZuWangFromJSRes zuWangFromJSRes) {
        //未组网的改为正常
        unZuwangDevice.setState(DeviceStateEnum.NORMAL.getType());
        unZuwangDevice.setIp(zuWangFromJSRes.getIp());
        deviceMapper.updateState(unZuwangDevice);
    }

    public static void updateDeviceUnNormal(DeviceMapper deviceMapper, Device unZuwangDevice, ZuWangFromJSRes zuWangFromJSRes) {
        //未组网的改为正常
        unZuwangDevice.setState(DeviceStateEnum.UN_NORMAL.getType());
        unZuwangDevice.setIp(zuWangFromJSRes.getIp());
        deviceMapper.updateState(unZuwangDevice);
    }

}
